/*
 * Created by SharpDevelop.
 * Author: Joey
 * Date: 27/09/2007
 * Time: 19:37
 * 
 * Source is copyright Joey Sabey 2007
 */

using System;
using System.Xml;

namespace MonoTheism
{
	/// <summary>
	/// Description of Options.
	/// </summary>
	public static class Options
	{
		private static String_List slAutoBuild = new String_List();
		public static String_List AutoBuild
		{
			get{return slAutoBuild;}
			set{slAutoBuild = value;}
		}
		private static bool bLongTermLog = true;
		public static bool LongTermLog
		{
			get{return bLongTermLog;}
		}
		private static string sMetaName = "";
		public static string MetaName
		{
			get{return sMetaName;}
		}
		
		public static void Clear()
		{
			slAutoBuild = new String_List();
		}
		
		public static void Save()
		{
			XmlDocument xmlOptions = new XmlDocument();
			xmlOptions.Load("options.xml");
			XmlNode xnodeRoot = xmlOptions.DocumentElement;
			foreach(XmlNode xnodeTop in xnodeRoot.ChildNodes)
			{
				if(xnodeTop.Name == "build")
				{
					foreach(XmlNode xnodeSecond in xnodeTop.ChildNodes)
					{
						if(xnodeSecond.Name == "autobuild")
						{
							xnodeSecond.RemoveAll();
							foreach(string s in slAutoBuild)
							{
								XmlElement element = xmlOptions.CreateElement("location");
								element.AppendChild(xmlOptions.CreateTextNode(s));
								xnodeSecond.AppendChild(element);
							}
						}
					}
				}
			}
			xmlOptions.Save("options.xml");
		}
		
		public static void Load()
		{
			XmlDocument xmlOptions = new XmlDocument();
			xmlOptions.Load("options.xml");
			XmlNode xnodeRoot = xmlOptions.DocumentElement;
			foreach(XmlNode xnodeTop in xnodeRoot.ChildNodes)
			{
				if(xnodeTop.Name == "build")
				{
					foreach(XmlNode xnodeSecond in xnodeTop.ChildNodes)
					{
						if(xnodeSecond.Name == "autobuild")
						{
							foreach(XmlNode xnodeThird in xnodeSecond.ChildNodes)
							{
								foreach(XmlText text in xnodeThird.ChildNodes)
								{
									Options.AutoBuild.Add(text.Value);
								}
							}
						}
					}
				}
			}
		}
	}
}
